<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


   
   
    <link rel="shortcut icon" href="favicon.ico"> <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    

</head>

<body class="gray-bg">

	<div class="modal inmodal fade" id="myModal5" tabindex="-1"
		role="dialog" aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
					</button>
					<small class="font-bold">新增路径规则
				</div>
				<div class="modal-body">
					<form id="myform">
						<div>
							<label>路径名称：</label><input type="text" name="pathName" />
						</div>
						<div>
							<label>路径说明：</label><input type="text" name="pathDescribe" />
						</div>
					</form>
				</div>

				<div class="modal-footer">
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" id="saveButton">保存</button>
				</div>
			</div>
		</div>
	</div>
	
	<div class="modal inmodal fade" id="myModal6" tabindex="-1"
		role="dialog" aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
					</button>
					<small class="font-bold">新增路径细则
				</div>
				<div class="modal-body">
					<form id="detailform">
						<div>
						<input type="hidden" name = "pathId" id = "pathId"/>
							<label>门禁：</label><select name="deviceIdentifier" id="deviceIdentifier"></select>
						</div>
						<div>
							<label>进出：</label>
							<input type="radio" name = "inOrOut" value="0" checked="checked">不限
							<input type="radio" name = "inOrOut" value="1">只能进
							<input type="radio" name = "inOrOut" value="2">只能出
						</div>
					</form>
				</div>

				<div class="modal-footer">
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" id="saveDetailButton">保存</button>
				</div>
			</div>
		</div>
	</div>

	<div class="wrapper wrapper-content animated fadeInRight">

        <!-- Panel Other -->
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <button value="新增" style="width: 60px;height: 30px"  data-toggle="modal" data-target="#myModal5">新增</button>
                <div class="ibox-tools">
                </div>
            </div>
            <div class="ibox-content">
                <div class="row row-lg">
                    <div class="col-sm-12">
                        <!-- Example Card View -->
                        <div class="example-wrap">
                            
                            <div class="example">
                                <table id="myTable" >
                                    
                                </table>
                            </div>
                        </div>
                        <!-- End Example Card View -->
                    </div>

                </div>
            </div>
        </div>
        <!-- End Panel Other -->
		
    </div>

    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="js/content.js?v=1.0.0"></script>


    <!-- Bootstrap table -->
    <script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>


 <script src="js/aivms5.js"></script>

<script>
var control_url = aivms5_control_url; 

window.operateEvents={
        "click a.edit":function(e,value,row,index){
        	e.stopPropagation();
        //   alert(row.id);
        	$("#myModal6").modal("show");
        	$("#pathId").val(row.id);
        },
        "click a.del":function(e,value,row,index){
           e.stopPropagation();
           delDetail(row.id);
        }
}

 $("#myTable").bootstrapTable({
        url:control_url + "/path/list", 
        method:'post',
        cache:false,
        pagination:true,
        sortable:false,
        sidePagination:"client",
        pageNumber:1,
        pageSize:10,
        search:false,
        uniqueId:'id',
        showRefresh: false,
        queryParams: queryParams,//传递参数（*）
		contentType: "application/x-www-form-urlencoded",
		ajaxOptions:{
          headers: {"token":"aaaa"}
        },
        clickToSelect:true,
        detailView:true,
        onExpandRow: function (index, row, $detail) {
        	detailTable(index, row, $detail);
        },
        columns:[
			{  
			    formatter: function (value, row, index) {  
			        return index+1;  
			    }  
			},
			{
                field:"checked",
                checkbox : true
            },
			{
			    field:"pathName",
			    title:"路径名称"
			},
            {
                field:"pathDescribe",
                title:"路径说明"
            },
            {
                field:"createdate",
                title:"创建时间"
            },
            {
                field:"operation",
                title:"操作",
                events:operateEvents,
                formatter:AddFunctionAlty
            }
          
        
        ]
    });

	  function queryParams(params) {
        var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            limit: params.limit,   //页面大小
            offset: params.offset,  //页码
           
        };
        return temp;
       };
       
       function AddFunctionAlty(value,row,index){
           return '<a class="edit">添加路径</a>';
       }
       
       
       
       
       $("#saveButton").click(function(){
       
       	var params = $("#myform").serialize();
               $.ajax( {  
                   type : "POST",  
                   url : control_url + "/path/addOrUpdate",  
                   data : params,  
                   success : function(data) {  
                   	if(data.code == 1000)
                   	{
                   		$("#myModal5").modal("hide");
                   		$("#myTable").bootstrapTable('refresh');
                   	}
                   	else
                   	{
                   		alert(data.msg)
                   	}
                   },
                   error: function(XMLHttpRequest, textStatus, errorThrown) {
                       alert("ajax请求发生错误");
                   }
               });  
       });
       
       
       
     //  var detailTable ;
       function detailTable(index, row, $detail)
       {
       	var cur_table = $detail.html('<table></table>').find('table');
     // 	detailTable = cur_table;
       	 $(cur_table).bootstrapTable({
                url:control_url + "/path/detailList?pathId="+row.id,
                method:'post',
                cache:false,
                pagination:true,
                sortable:false,
                sidePagination:"client",
                pageNumber:1,
                pageSize:5,
                pageList:[5,10,20,50],
                search:false,
                uniqueId:'id',
			
                showRefresh: false,
                clickToSelect:true,
                columns:[
					{  
					    formatter: function (value, row, index) {  
					        return index+1;  
					    }  
					},
                    {
	                     field:"deviceIdentifier",
	                     title:"设备标识"
                    },
                    {
                        field:"inOrOut",
                        title:"进出",
                        formatter: function (value, row, index) {
                           	 if(value == 0)
                            	 {
                           		 return "不限";
                            	 }
                                else  if(value == 1)
                                {
                                	return "只能进";
                                }
                                else  if(value == 2)
                                {
                                	return "只能出";
                                }
                            }
                    },
                    {
                        field:"createdate",
                        title:"添加时间"
                    },
                    {
                        field:"operation",
                        title:"操作",
                        events:operateEvents,
                        formatter: function (value, row, index) {
                        	return '<a class="del">删除</a>';
                        }
                    }
                
                ]
            })
       }
       
       $("#saveDetailButton").click(function(){
           
         	var params = $("#detailform").serialize();
                 $.ajax( {  
                     type : "POST",  
                     url : control_url + "/path/detailAddOrUpdate",  
                     data : params,  
                     success : function(data) {  
                     	if(data.code == 1000)
                     	{
                     		$("#myModal6").modal("hide");
                     		$("#myTable").bootstrapTable('refresh');
                     	}
                     	else
                     	{
                     		alert(data.msg)
                     	}
                     },
                     error: function(XMLHttpRequest, textStatus, errorThrown) {
                         alert("ajax请求发生错误");
                     }
                 });  
         });
       
       function delDetail(id)
       {
    	   $.ajax( {  
               type : "get",  
               url : control_url + "/path/delDetail?id="+id,  
               success : function(data) {  
               	if(data.code == 1000)
               	{
               		$("#myTable").bootstrapTable('refresh');
               	}
               	else
               	{
               		alert(data.msg)
               	}
               },
               error: function(XMLHttpRequest, textStatus, errorThrown) {
                   alert("ajax请求发生错误");
               }
           });  
       }
       
       
       $.ajax({
			type : "POST",
			url : aivms5_door_url+ "/entranceGuard/list",
			success : function(data) {

					var value = "";
					for (var i = 0; i < data.length; i++) {
						var obj = data[i];
						value += "<option value='"+obj.sn+"'>"+ obj.sn + "</option>"
					}
					$("#deviceIdentifier").append(value);
			},
			error : function(data) {
				alert(data);
			}
		});
</script>

</body>

</html>
